package com.engine.jucailinkq.attendance.workflow.cmd;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.jucailinkq.common.util.DbTools;
import com.engine.core.interceptor.CommandContext;
import lombok.extern.slf4j.Slf4j;
import weaver.general.Util;
import weaver.hrm.User;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class GetAskForLeaveRecordListCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetAskForLeaveRecordListCmd(Map<String, Object> params, User user) {
        this.user = user;
        this.params = params;
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> retmap = new HashMap<String, Object>();
        //获取主表id列表
        String targetUserId = Util.null2String(params.get("targetUserId"));
        String businessTripsType = Util.null2String(params.get("businessTripsType"));
        String startDate = Util.null2String(params.get("startDate"));
        String endDate = Util.null2String(params.get("endDate"));
        log.debug("targetUserId : {}, businessTripsType : {}, startDate : {}, endDate : {}", targetUserId, businessTripsType, startDate, endDate);

        String detailSql = "select a.id,a.cxqj,a.ksrq,a.kssj,a.jsrq,a.jssj,a.qjsc,a.qtj,a.btj,a.cxsm from uf_jcl_kq_qjjl_dt1 a   where (a.cxqj is null or a.cxqj<>1) and a.qjry =? and a.ksrq >= ? and a.ksrq <= ? and a.jqlx=?";
        List<Map<String, Object>> detailList = DbTools.getSqlToList(detailSql,targetUserId,startDate,endDate,businessTripsType);
        if (detailList.size() > 0) {
            retmap.put("result", detailList);
        } else {
            retmap.put("result", null);
        }
        log.debug("detailList : [{}]", detailList);

        return retmap;
    }
}
